package com.sanjin.convert;

import com.sanjin.dto.AuthCode2Session;
import com.sanjin.dto.WxUserInfo;
import com.sanjin.entity.WxMiniUser;
import com.sanjin.enums.RoleEnum;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * @description:
 * @author: sanjin
 * @date: 2019/5/10 18:23
 */
@Component
public class WxMiniUserConvert {

    public WxMiniUser wxUserInfo2WxMiniUser(WxUserInfo wxUserInfo, AuthCode2Session authCode2Session) {
        WxMiniUser wxMiniUser = new WxMiniUser();

        wxMiniUser.setImageUrl(wxUserInfo.getAvatarUrl());
        wxMiniUser.setNickname(wxUserInfo.getNickname());
        wxMiniUser.setOpenid(authCode2Session.getOpenid());
        wxMiniUser.setSessionKey(authCode2Session.getSession_key());
        // 微信用户初始化积分为100
        wxMiniUser.setBonusPoints(new BigDecimal(100));
        // 微信用户默认角色为
        wxMiniUser.setRole(RoleEnum.WX_MINI_USER.roleName);
        return wxMiniUser;
    }

}
